package icu.lingjie.controller;

import icu.lingjie.service.LingJieService;
import icu.lingjie.service.LingZhenService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.util.FileCopyUtils;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpServletResponse;
import java.io.ByteArrayInputStream;
import java.nio.charset.StandardCharsets;

@CrossOrigin
@Controller
public class LingJieApi {

    @Autowired
    LingJieService lingJieService;

    @Autowired
    LingZhenService lingZhenService;

    @GetMapping("/test")
    public void test(HttpServletResponse response) throws Exception{
        final ByteArrayInputStream in = new ByteArrayInputStream("<h1>卧槽<h1>".getBytes(StandardCharsets.UTF_8));
        response.setContentType("text/html; charset=utf-8");
        FileCopyUtils.copy(in, response.getOutputStream());
    }

    @GetMapping("/points")
    public void getPointsForWeb(HttpServletResponse response,
                                @RequestParam(value = "x", defaultValue = "0") int x,
                                @RequestParam(value = "y", defaultValue = "0") int y,
                                @RequestParam(value = "z", defaultValue = "0") int z) throws Exception{
        lingJieService.getPointsForWeb(x,y,z, response);
    }
}
